<?php


    if (!empty($_POST)) {


        //print_r($_SERVER);die;
        //
        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {

            $pid = $_POST['pid'];
            $sql = "select * from `cate` where `pid`='$pid'";

            $result = mysqli_query($link,$sql);

            while ($arr = mysqli_fetch_assoc($result)){

                $data[] = $arr;
            };

            print_r(json_encode($data));die;

        };



        //print_r($_POST);die;
        $name = $_POST['name'];
        $pid = $_POST['pid'];

        $sql = "insert into `cate` (`name`,`pid`) values ('$name','$pid')";

        mysqli_query($link,$sql);
        $_rows = mysqli_affected_rows($link);
        if ($_rows > 0) {
            echo '<script type="text/javascript">alert("添加成功！");self.location.href="index.php?c=cate&a=list&admin=1";</script>';die;
        }else{
            echo '<script type="text/javascript">alert("添加失败！");history.go(-1);</script>';die;
        }
    }




?>